home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_qt.idb / usr / freeware / include / Qt / qgl.h.z / qgl.h
Encoding:
C/C++ Source or Header  |  1998-10-28  |  5.6 KB  |  293 lines

  1. /****************************************************************************
  2. ** $Id: qgl.h,v 1.9 1998/07/03 00:09:27 hanord Exp $
  3. **
  4. ** Definition of OpenGL classes for Qt
  5. **
  6. ** Created : 970112
  7. **
  8. ** Copyright (C) 1992-1998 Troll Tech AS.  All rights reserved.
  9. **
  10. ** This file is part of Qt Free Edition, version 1.40.
  11. **
  12. ** See the file LICENSE included in the distribution for the usage
  13. ** and distribution terms, or http://www.troll.no/free-license.html.
  14. **
  15. ** IMPORTANT NOTE: You may NOT copy this file or any part of it into
  16. ** your own programs or libraries.
  17. **
  18. ** Please see http://www.troll.no/pricing.html for information about 
  19. ** Qt Professional Edition, which is this same library but with a
  20. ** license which allows creation of commercial/proprietary software.
  21. **
  22. *****************************************************************************/
  23.  
  24. #ifndef QGL_H
  25. #define QGL_H
  26.  
  27.  
  28. #define QGL_VERSION    200
  29. #define QGL_VERSION_STR    "2.0b"
  30.  
  31. const char *qGLVersion();
  32.  
  33.  
  34. #ifndef QT_H
  35. #include <qwidget.h>
  36. #endif // QT_H
  37.  
  38. #if !(defined(Q_WGL) || defined(Q_GLX))
  39. #if defined(_OS_WIN32_)
  40. #define Q_WGL
  41. #else
  42. #define Q_GLX
  43. #endif
  44. #endif
  45. #if defined(Q_WGL)
  46. #include <windows.h>
  47. #endif
  48. #include <GL/gl.h>
  49. #include <GL/glu.h>
  50.  
  51.  
  52. class QGLFormat
  53. {
  54. public:
  55.     QGLFormat( bool doubleBuffer=TRUE );
  56.     QGLFormat( const QGLFormat& f );
  57.     virtual ~QGLFormat();
  58.  
  59.     QGLFormat&        operator=( const QGLFormat& f );
  60.  
  61.     bool            doubleBuffer() const;
  62.     void            setDoubleBuffer( bool enable );
  63.     bool            depth() const;
  64.     void            setDepth( bool enable );
  65.     bool            rgba() const;
  66.     void            setRgba( bool enable );
  67.     bool            alpha() const;
  68.     void            setAlpha( bool enable );
  69.     bool            accum() const;
  70.     void            setAccum( bool enable );
  71.     bool            stencil() const;
  72.     void            setStencil( bool enable );
  73.     bool            stereo() const;
  74.     void            setStereo( bool enable );
  75.  
  76.     static const    QGLFormat &defaultFormat();
  77.     static void        setDefaultFormat( const QGLFormat& f );
  78.  
  79.     static bool        hasOpenGL();
  80.  
  81. private:
  82.  
  83.     struct FormatFlags : public QShared {
  84.     bool    doubleBuffer;
  85.     bool    depth;
  86.     bool    rgba;
  87.     bool    alpha;
  88.     bool    accum;
  89.     bool    stencil;
  90.     bool    stereo;
  91.     };
  92.  
  93.     void        detach();
  94.     FormatFlags*    data;
  95. };
  96.  
  97.  
  98. class QGLContext
  99. {
  100. public:
  101.     QGLContext( const QGLFormat& format, QPaintDevice* device );
  102.     virtual ~QGLContext();
  103.  
  104.     bool        create( const QGLContext* shareContext = 0 );
  105.     bool        isValid() const;
  106.     void        reset();
  107.  
  108.     const QGLFormat&    format() const;
  109.     void        setFormat( const QGLFormat& format );
  110.  
  111.     void        makeCurrent();
  112.     void        swapBuffers();
  113.  
  114.     QPaintDevice*    device() const;
  115.  
  116. protected:
  117.     bool        chooseContext( const QGLContext* shareContext = 0 );
  118.     void        doneCurrent();
  119.  
  120. #if defined(Q_WGL)
  121.     virtual int        choosePixelFormat( void* pfd );
  122. #elif defined(Q_GLX)
  123.     virtual void*    chooseVisual();
  124. #endif
  125.  
  126. protected:
  127. #if defined(Q_WGL)
  128.     HANDLE        rc;
  129.     HANDLE        dc;
  130.     HANDLE        win;
  131. #elif defined(Q_GLX)
  132.     void*        vi;
  133.     void*        cx;
  134. #endif
  135.  
  136. private:
  137.     bool        valid;
  138.     QGLFormat        glFormat;
  139.     QPaintDevice*    paintDevice;
  140.  
  141.     friend class QGLWidget;
  142.  
  143. private:    // Disabled copy constructor and operator=
  144.     QGLContext() {}
  145.     QGLContext( const QGLContext& ) {}
  146.     QGLContext&        operator=( const QGLContext& ) { return *this; }
  147. };
  148.  
  149.  
  150. class QGLWidget : public QWidget
  151. {
  152.     Q_OBJECT
  153. public:
  154.     QGLWidget( QWidget* parent=0, const char* name=0,
  155.            const QGLWidget* shareWidget = 0, WFlags f=0 );
  156.     QGLWidget( const QGLFormat& format, QWidget* parent=0, const char* name=0,
  157.            const QGLWidget* shareWidget = 0, WFlags f=0 );
  158.    ~QGLWidget();
  159.  
  160.     bool        isValid() const;
  161.  
  162.     void        makeCurrent();
  163.     bool        doubleBuffer() const;
  164.     void        swapBuffers();
  165.  
  166.     const QGLFormat&    format() const;
  167.     void        setFormat( const QGLFormat& format );
  168.  
  169.     const QGLContext*    context() const;
  170.     void        setContext( QGLContext* context, 
  171.                     const QGLContext* shareContext = 0 );
  172.  
  173. public slots:
  174.     void        updateGL();
  175.  
  176. protected:
  177.     virtual void    initializeGL();
  178.     virtual void    paintGL();
  179.     virtual void    resizeGL( int w, int h );
  180.  
  181.     void        paintEvent( QPaintEvent* );
  182.     void        resizeEvent( QResizeEvent* );
  183.  
  184. private:
  185.     void        gl_init();
  186.     bool        initDone;
  187.     QGLContext*        glcx;
  188.  
  189. private:    // Disabled copy constructor and operator=
  190.     QGLWidget( const QGLWidget& ) {}
  191.     QGLWidget&        operator=( const QGLWidget& ) { return *this; }
  192. };
  193.  
  194.  
  195. //
  196. // QGLFormat inline functions
  197. //
  198.  
  199. inline bool QGLFormat::doubleBuffer() const
  200. {
  201.     return data->doubleBuffer;
  202. }
  203.  
  204. inline bool QGLFormat::depth() const
  205. {
  206.     return data->depth;
  207. }
  208.  
  209. inline bool QGLFormat::rgba() const
  210. {
  211.     return data->rgba;
  212. }
  213.  
  214. inline bool QGLFormat::alpha() const
  215. {
  216.     return data->alpha;
  217. }
  218.  
  219. inline bool QGLFormat::accum() const
  220. {
  221.     return data->accum;
  222. }
  223.  
  224. inline bool QGLFormat::stencil() const
  225. {
  226.     return data->stencil;
  227. }
  228.  
  229. inline bool QGLFormat::stereo() const
  230. {
  231.     return data->stereo;
  232. }
  233.  
  234. //
  235. // QGLContext inline functions
  236. //
  237.  
  238. inline bool QGLContext::isValid() const
  239. {
  240.     return valid;
  241. }
  242. inline const QGLFormat& QGLContext::format() const
  243. {
  244.     return glFormat;
  245. }
  246.  
  247. inline QPaintDevice* QGLContext::device() const
  248. {
  249.     return paintDevice;
  250. }
  251.  
  252. //
  253. // QGLWidget inline functions
  254. //
  255.  
  256. inline bool QGLWidget::isValid() const
  257. {
  258.     return glcx->isValid();
  259. }
  260.  
  261. inline void QGLWidget::makeCurrent()
  262. {
  263.     glcx->makeCurrent();
  264. }
  265.  
  266. inline bool QGLWidget::doubleBuffer() const
  267. {
  268.     return glcx->format().doubleBuffer();
  269. }
  270.  
  271. inline void QGLWidget::swapBuffers()
  272. {
  273.     glcx->swapBuffers();
  274. }
  275.  
  276. inline const QGLFormat &QGLWidget::format() const
  277. {
  278.     return glcx->format();
  279. }
  280.  
  281. inline const QGLContext *QGLWidget::context() const
  282. {
  283.     return glcx;
  284. }
  285.  
  286. inline void QGLWidget::updateGL()
  287. {
  288.     repaint( FALSE );
  289. }
  290.  
  291.  
  292. #endif // QGL_H
  293.